package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.bean.pagebean.XiaoXiXiangQingBean;
import com.oscar.ehome.bean.pagebean.XueXiListBean;
import com.oscar.ehome.provider.gildeimage.GildeUtils;
import com.oscar.ehome.utils.system.SystemConfigFactory;
import com.oscar.ehome.utils.util.DateUtil;
import com.oscar.ehome.view.pageview.FrequencyActivity;
import com.oscar.ehome.view.pageview.PdfDetialActivity;
import com.oscar.ehome.view.pageview.StudyFinalActivity;
import com.oscar.ehome.view.pageview.StudyTongJiListActivity;
import com.oscar.ehome.view.pageview.VideoActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/12/18
 */

public class StudyLIstAdapter extends BaseAdapter {

    private List<XueXiListBean.xiangxin> list = new ArrayList<>();
    private LayoutInflater mInflater;
    private Context mContext = null;
    XueXiListBean.xiangxin bean;

    public StudyLIstAdapter(Context context, List<XueXiListBean.xiangxin> list) {
        this.mContext = context;
        this.list = list;
        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<XueXiListBean.xiangxin> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        StudyLIstAdapter.ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.studytongjiitem, null);
            holder = new StudyLIstAdapter.ViewHolder();
            holder.xuexitongjiren = (TextView) convertView.findViewById(R.id.xuexitongjiren);
            holder.xuexitongjitu = (ImageView) convertView.findViewById(R.id.xuexitongjitu);
            holder.xuexitongjitime = (TextView) convertView.findViewById(R.id.xuexitongjitime);
            holder.xuexitongjinum = (TextView) convertView.findViewById(R.id.xuexitongjinum);
            holder.xuexitongjititle = (TextView) convertView.findViewById(R.id.xuexitongjititle);


            convertView.setTag(holder);
        } else {
            holder = (StudyLIstAdapter.ViewHolder) convertView.getTag(); //
        }

        if (list.size() > 0) {
            bean = list.get(position);
            if (bean != null) {
                holder.xuexitongjititle.setText(bean.getTitle());
                holder.xuexitongjiren.setTextColor(Color.parseColor(SystemConfigFactory.getInstance(mContext).getSystemConfig().getColor()));
                holder.xuexitongjinum.setTextColor(Color.parseColor(SystemConfigFactory.getInstance(mContext).getSystemConfig().getColor()));
                holder.xuexitongjinum.setText(bean.getReadNum());
                //  String date = DateUtil.timeLogic(bean.getCreateDate());

                holder.xuexitongjitime.setText(bean.getCreateDate());
                String importurl = C.qiniu_ip + bean.getSmallImg();
                String learnType = bean.getLearnType();
                if ("video/mp4".equals(learnType)) {//视频
                    GildeUtils.loadUrlImageshipin(importurl, holder.xuexitongjitu, mContext);
                } else if ("application/pdf".equals(learnType)) {//PDF
                    GildeUtils.loadUrlImagepdf(importurl, holder.xuexitongjitu, mContext);
                } else if ("audio/mp3".equals(learnType)) {//音频
                    GildeUtils.loadUrlImageyinpin(importurl, holder.xuexitongjitu, mContext);
                }else if ("application/vnd.ms-excel".equals(learnType) || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".equals(learnType)) {//音频
                    GildeUtils.loadUrlImageexcel(importurl, holder.xuexitongjitu, mContext);
                }


            }
        }
        return convertView;
    }

    class ViewHolder {
        TextView xuexitongjiren;
        TextView xuexitongjitime;//
        TextView xuexitongjinum;
        TextView xuexitongjititle;
        ImageView xuexitongjitu;
    }

}
